﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// LightStreakEffect Effect
    /// </summary>
    public class LightStreakEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(LightStreakEffect), 0);
        public static readonly DependencyProperty BrightThresholdProperty = DependencyProperty.Register("BrightThreshold", typeof(double), typeof(LightStreakEffect), new UIPropertyMetadata(0.25, ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register("Scale", typeof(double), typeof(LightStreakEffect), new UIPropertyMetadata(0.75, ShaderEffect.PixelShaderConstantCallback(1)));
        public static readonly DependencyProperty AttenuationProperty = DependencyProperty.Register("Attenuation", typeof(double), typeof(LightStreakEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(2)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(LightStreakEffect.InputProperty));
            }
            set
            {
                this.SetValue(LightStreakEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété BrightThreshold du Shader
        /// </summary>
        public double BrightThreshold
        {
            get
            {
                return ((double)this.GetValue(LightStreakEffect.BrightThresholdProperty));
            }
            set
            {
                this.SetValue(LightStreakEffect.BrightThresholdProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Scale du Shader
        /// </summary>
        public double Scale
        {
            get
            {
                return ((double)this.GetValue(LightStreakEffect.ScaleProperty));
            }
            set
            {
                this.SetValue(LightStreakEffect.ScaleProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Attenuation du Shader
        /// </summary>
        public double Attenuation
        {
            get
            {
                return ((double)this.GetValue(LightStreakEffect.AttenuationProperty));
            }
            set
            {
                this.SetValue(LightStreakEffect.AttenuationProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static LightStreakEffect()
        {
            LightStreakEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/LightStreak.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public LightStreakEffect()
        {
            this.PixelShader = LightStreakEffect._PixelShader;

            this.UpdateShaderValue(InputProperty);
            this.UpdateShaderValue(BrightThresholdProperty);
            this.UpdateShaderValue(ScaleProperty);
            this.UpdateShaderValue(AttenuationProperty);
        }

        #endregion
    }
}
